package com.example.vote.controller;

import com.example.vote.entity.User;
import com.example.vote.mapper.UserMapper;
import com.example.vote.vo.Result;
import com.yc.upload.vo.UploadProperties;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 投票系统-用户表-4 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/vote/user")
public class UserController {
    @Resource
    UserMapper userMapper;

    @RequestMapping("upuser")
    public Result upuser(@RequestBody User user) {
        int up1 = userMapper.updateById(user);
        if(up1 == 1){
            return new  Result(1,"更新成功",null);
        }
        else{
            return new  Result(0,"更新失败",null);
        }

    }


    @RequestMapping("selectUser")
    public Result selectUser(HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("loginedUser");

        User user1 = userMapper.selectById(user.getId());
        System.out.println(user1);
        if(user1!= null){
            return new  Result(1,"查询成功",user1);
        }
        else{
            return new  Result(0,"查询失败",null);
        }

    }









}
